package huanzhao.erp.other.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
 * @author April
 * @version 1.0
 */
@Slf4j
public class GlobalInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String requestURI = request.getRequestURI();
        String queryString = request.getQueryString();
        if (queryString != null) {
            requestURI += "?" + queryString;
        }
        String decodedURI = URLDecoder.decode(requestURI, StandardCharsets.UTF_8);
        log.info("{}，{} {}", request.getRemoteAddr(), request.getMethod(), decodedURI);
        return true;
    }
}
